#include "mpu6050.h"
#include "stdio.h"
#include "iic.h"
#include "unistd.h"
#include <sys/time.h>

extern double last_Seconds;
 
int main(void)
{
	 iic_init();//IIC载入
     MPU_Init();//MPU6050初始化
	 sleep(1);//等待稳定
     MPU_init_Offset();//加速度计/陀螺仪校准
     printf("MPU6050 init & offset OK \r");
	 sleep(2);

    {
        struct timeval cur_time;
        gettimeofday(&cur_time, NULL);  
        last_Seconds = cur_time.tv_sec + cur_time.tv_usec/1000000.0;
    }

     while (1)
     {
        MPU_Get_Gyroscope(&gyrox, &gyroy, &gyroz);  //读取陀螺仪
        MPU_Get_Accelerometer(&aacx, &aacy, &aacz);  //读取加速度计
        Gyro_Change();//陀螺仪角速度转换
        Acc_Change();//加速度计加速度转换
        Angle_Get();//获得角度
        //printf("  %.1f %.1f %.1f \n", Angle_Pitch, Angle_Roll, Angle_Yaw);//打印角度
        usleep(1000);//延时1ms
        //printf("temperature: %.2f\n", MPU_Get_Temperature()/100.0);
    }

    return 0;
}